﻿Imports System.Data.SqlClient
Imports System.Web.Security
Imports System.Security.Cryptography

Partial Class register
    Inherits System.Web.UI.Page

    Protected Sub btnAddCredentials_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddCredentials.Click
        Dim userAdapter As New MainDbTableAdapters.UsersTableAdapter()
        Dim roleAdapter As New MainDbTableAdapters.RolesTableAdapter()
        Dim intSaltSize As Integer = 16
        Dim objByte() As Byte = New Byte(intSaltSize) {}
        Dim objRng As New RNGCryptoServiceProvider
        Dim strSalt As String = Convert.ToBase64String(objByte)
        Dim FName As String = txtFName.Text
        Dim LName As String = txtLName.Text
        Dim BirthDate = txtBirthDate.Text
        Dim Email As String = txtEmail.Text
        Dim Password As String = FormsAuthentication.HashPasswordForStoringInConfigFile(strSalt + txtPassword.Text, "SHA1")
        Dim isPrivate = "False"
        Dim userID As Integer
        Dim role As Integer = 3 'superuser role

        objRng.GetBytes(objByte)
        userID = userAdapter.InsertUserShort(FName, LName, BirthDate, Email, Password, strSalt, isPrivate)

        roleAdapter.Insert(userID, role)

        Response.Redirect("login.aspx?status=1")

    End Sub
End Class
